Ext.define('Form.controller.main.loginchangepwdrequest', {
    extend: 'Ext.app.Controller',

	views: [
        'main.loginformchangepwdrequest'
    ],
	
	stores: [
		//'Users'
	],
	
	models: [
		//'User'
	],
	
    init: function() {
        this.control({
            'viewport > panel': {
                render: this.onPanelRendered
            },
			'littleloginformchangepwdrequest button[action=signin]': {
				click: this.logYouIn
			},
			'littleloginformchangepwdrequest textfield': {
				specialkey: this.logYouIn
			}
		
        });
        
    },

    onPanelRendered: function() {
        console.log('The login panel was rendered');
    },
	
	logYouIn: function(button, e) {
		if(e.type == 'keydown')
		{
			if(e.getKey() != e.ENTER) { 
		         return true;
		    } 
	    }
		console.log('logyouin');
		if (button.up('form').getForm().isValid()) {
			Ext.get(button.up('form').getEl()).mask("Authenticating...", 'loading');
		  	button.up('form').submit({
		  		url: 'blank.cfm',
		  		reset: true,
		  		method: 'POST',
		  		failure: function(form, action){
		  			Ext.get(button.up('form').getEl()).unmask();	
		  		},
		  		success: function(form, action){
		  			Ext.get(button.up('form').getEl()).unmask();
		  			console.log(form);
		  			console.log(action);
					if (action.result.form[0].detail=='yessuccessdetail') 
					{
						window.location.href = './?bdg=' + action.result.form[0].message;
					} else if ( action.result.form[0].detail=='changepassword' ) {
						alert('Please change password here...');
					} else
					{
						form.setValues([{
							id: 'displayrespidid',
							value: action.result.form[0].detail
						}]);
					}
		  			
		  		}
	  	});
	  } 
	}
	
});